#include "main.h"

volatile unsigned char  red_value=0;
volatile unsigned char  fengshan_value=0;

/**
  * @brief  灯和风扇的初始化函数
**/
void LED_Init(void)
{
    GPIO_InitTypeDef GPIO_InitStructure;
    //PC7--对应灯;PC8--对应风扇；
    RCC_APB2PeriphClockCmd (RCC_APB2Periph_GPIOC, ENABLE);
    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7|GPIO_Pin_8;
    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
    GPIO_Init(GPIOC, &GPIO_InitStructure);
}


/**
  * @brief  分析平台下发的LED控制命令
**/
void LED_CmdCtl(void)
{
		printf("%s\n",usart2_cmd_buf);
		if((NULL != strstr((const char *)usart2_cmd_buf, "LED1")))  //约定平台控制命令"LED1"为打开灯
		{
				LED_RED_ON;	
				red_value=1;
		}
		if((NULL != strstr((const char *)usart2_cmd_buf, "FengShan1")))  //约定平台控制命令"FengShan1"为打开风扇
		{
				FengShan_ON;	
				fengshan_value=1;
		}		
		if((NULL != strstr((const char *)usart2_cmd_buf, "LED0")))  //约定平台控制命令"LED0"为关闭灯
		{
				LED_RED_OFF;	
				red_value=0;
		}
		if((NULL != strstr((const char *)usart2_cmd_buf, "FengShan0")))  //约定平台控制命令"FengShan0"为关闭风扇
		{
				FengShan_OFF;
				fengshan_value=0;	
		}
}

/**
  * @brief  LED指示灯操作函数，点亮和熄灭指示灯
**/
void LED_Switch(const uint8_t statu,const uint8_t mode)
{
		if(statu)
		{
				LED_RED_OFF;
				FengShan_OFF;
			
				if(mode&0x01)
				{
						LED_RED_ON;
				}
				if(mode&0x02)
				{
						FengShan_ON;
				}
		}
		else
		{
				if(mode&0x01)
				{
						LED_RED_OFF;
				}
				if(mode&0x02)
				{
						FengShan_OFF;
				}
		}
}


/**
  * @brief  获取LED的当前状态值
**/
void LED_GetValue(void)
{
		if(GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_7))
		{
				red_value=1;
		}
		else
		{
				red_value=0;
		}
		if(GPIO_ReadOutputDataBit(GPIOC, GPIO_Pin_8))//light
		{
				fengshan_value=1;
		}
		else
		{
				fengshan_value=0;
		}
}







